package br.com.sol.controle;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import android.bluetooth.BluetoothSocket;

public class ThreadComunicacao extends Thread {

	String nome;
	BluetoothSocket socket;
	private DataInputStream is;
	private DataOutputStream os;
	
	public void run() {
		try {
			nome = socket.getRemoteDevice().getName();
			is = new DataInputStream(socket.getInputStream());
			os = new DataOutputStream(socket.getOutputStream());
			
			String string;
			while (true) {
				string = is.readUTF();
				//telaHandler.obtainMessage(MSG_TEXTO, nome +": "+ string).sendToTarget();
			}
			
		} catch (IOException e) {
			e.printStackTrace();
			//telaHandler.obtainMessage(MSG_DESCONECTOU, e.getMessage()+"[3]").sendToTarget();
		}
	}
	
	public void iniciar(BluetoothSocket socket){
		this.socket = socket;
		start();
	}
	
	public void parar(){
		try {
			is.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			os.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
